/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/** 
 * \file
 * \brief Simple test class for MottiTask parser.
 * \author Antti Maula <antti.maula@tkk.fi>
 *
 * This file contains a simple stand-alone tester for the
 * CMottiMission class. It is by no means intended to be used in real
 * applications and is purely for debugging/testing and verification
 * purposes.
 */

#include "MottiMission.hpp"
#include "owndebug.h"
#include <assert.h>
#include <stdio.h>


//*****************************************************************************
//*****************************************************************************

int main(int argc, char *argv[])
{
  Motti::CMission mm;
  bool r;
  std::string sourcefile = "rocla_task.xml";
  std::string targetfile = "";

  // If only one param (or more); use 1st as sourcefile
  if (argc > 1) {
    sourcefile = argv[1];
  }

  // If two params, (or more); use 2nd as targetfile.
  if (argc > 2) {
    targetfile = argv[2];
  }

  // Normal debug lib inits.
  debugInit();
  debugSetGlobalDebugLvl(5);

  // Now call DecodeMottiMissionXMLFile to decode the XML file.
  // Function should return true for valid files, so for here we'll
  // check the result with assert.
  r = mm.DecodeMottiMissionXMLFile(sourcefile);
  assert( r == true );

  // Get constant reference to the decoded mission tree.
  const Motti::SMission &mission = mm.GetMission();

  // Print
  printf("\n%s\n", mission.ToXMLString().c_str());

  // ... and if targetfilename is set; write the same information to
  // the file as well.
  if (targetfile.size()) {
    FILE *f = fopen(targetfile.c_str(), "w");
    if (f) {
      fprintf(f, "%s\n", mission.ToXMLString().c_str());
      fclose(f);
    }
  }

  // Now little smoke testing.
  bool ar,br;
  Motti::CMission a,b,c;
  ar = a.EncodeMottiMission(mm.GetMission(), true);
  assert ( ar == true );

  int iterate=100;
  while(--iterate) {
    br = b.DecodeMottiMissionXML(a.GetMissionXML(), true);
    assert(br);
    ar = a.EncodeMottiMission(b.GetMission(), true);
    assert(ar);
  }
  
  

  return 0;
}
//*****************************************************************************
//*****************************************************************************
